package com.tanger.permission.permission.web;

import com.tanger.common.exception.AbstractController;
import com.tanger.common.result.ActionResult;
import com.tanger.common.utils.StringUtil;
import com.tanger.permission.entity.permission.EntityPermission;
import com.tanger.permission.permission.service.PermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 控制层
 */
@RestController
@RequestMapping("/tanger/bts/permission")
@Api(value = "权限",tags="权限")
public class PermissionController extends AbstractController {

	@Autowired
	private PermissionService permissionService;

	private final Logger logger = LoggerFactory.getLogger(getClass());

	@ApiImplicitParam(name = "id", value = "主键ID", required = true, dataType = "Long")
	@ApiOperation(value = "权限详情")
	@GetMapping("/{id}")
	public ActionResult<EntityPermission> getInfo(@PathVariable Long id) {
		try {
			if (StringUtil.isNull(id)) return ActionResult.buildResultError("参数缺失");
			return permissionService.permissionInfo(id,null);
		} catch (Exception e) {
			return ActionResult.buildResultError(e.getMessage());
		}
	}


	@ApiOperation(value = "权限树形列表")
	@GetMapping(value = "/permissionTreeList")
	public ActionResult permissionTreeList() {
		try {
			return permissionService.queryPermissionList(null);
		} catch (Exception e) {
			return ActionResult.buildResultError(e.getMessage());
		}
	}
}